package cn.edu.tsinghua.training.maven.test.demo.action;

import org.apache.commons.codec.digest.DigestUtils;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import cn.edu.tsinghua.training.maven.test.demo.entity.User;

public class UserAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private User user;
	private SessionFactory sessionFactory;
	
	public String register() throws Exception {
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		user.setPassword(DigestUtils.md5Hex(user.getPassword()));
		session.save(user);
		transaction.commit();
		session.close();
		return "register_success";
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

}
